package com.itbaima.edu.info.manager.service;

import com.itbaima.edu.info.manager.dao.TeacherDao;
import com.itbaima.edu.info.manager.domain.Teacher;

/**
 * Created by byakuya on 2020/8/5
 */
public class TeacherService {
    //库管对象
    private final TeacherDao teacherDao = new TeacherDao();
    public boolean addTeacher(Teacher t) {
        return teacherDao.addTeacher(t);
    }

    public boolean isExists(String id) {
        //获取库管对象中的数组
        Teacher[] teachers = teacherDao.findAllTeacher();
        //遍历数组，取出每个元素进行判断
        for (Teacher teacher : teachers) {
            if (teacher != null && teacher.getId().equals(id))
                return true;
        }
        return false;
    }

    public Teacher[] findAllTeacher() {
        Teacher[] teachers = teacherDao.findAllTeacher();
        for (Teacher teacher : teachers) {
            if (teacher != null)
                return teachers;
        }
        return null;
    }

    public void deleteTeacherById(String id) {
        teacherDao.deleteTeacherById(id);
    }

    public void updateTeacher(String id, Teacher newTeacher) {
        teacherDao.updateTeacher(id, newTeacher);
    }
}
